package com.ruoyi.project.app;

import com.ruoyi.framework.aspectj.lang.annotation.Anonymous;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.project.ins.domain.InsAccount;
import com.ruoyi.project.ins.service.IInsAccountService;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Anonymous
@RestController
@RequestMapping("/app/ins/account")
public class AppInsAccountController extends BaseController {
    @Autowired
    private IInsAccountService insAccountService;

    @PostMapping
    public AjaxResult add(@Validated @RequestBody InsAccount insAccount) {
        if (StringUtils.isBlank(insAccount.getUserId())) {
            return error("用户id不存在");
        }
        InsAccount ins = insAccountService.selectByUserId(insAccount.getUserId());
        if (ObjectUtils.isNotEmpty(ins)) {
            return error("该用户id已存在：" + insAccount.getUserId());
        }
        insAccount.setSourceType("0");
        insAccount.setStatus("0");
        insAccount.setSendTimes(0);
        return toAjax(insAccountService.insertInsAccount(insAccount));
    }
}
